package dao.impl;

import dao.UserDao;
import pojo.entity.User;
import util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 对表数据的持久化层的接口
 *
 */
public class UserDaoImpl implements UserDao {
    public boolean loginByUsernameAndPwd(User user){
        String sql = "select * from user where username = ?";
        Object[] params = {user.getUsername()};
        ResultSet set = JDBCDruidUtil.query(sql, params);
        if(set != null){
            try{
                while(set.next()){
                    if(user.getPassword().equals(set.getString("password"))){
                        return true;
                    }
                }
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
        return false;
    }
}
